package asteroids.model.programs.expression;

import asteroids.model.programs.type.*;

public class DifferentFrom extends Comparision {

	public DifferentFrom(int line, int column, E left, E right) {
		super(line, column, left, right);
	}

	@Override
	public Bool getValue() {
		if(getRight().getValue() == null || getLeft().getValue() == null){
			if(getRight().getValue() == null && getLeft().getValue() == null)
				return new Bool(false);
			else 
				return new Bool(true);
		}
		if(getRight().getValue().getClass() == DoubleType.class)
			return new Bool(((DoubleType) getRight().getValue()).getValue() != ((DoubleType) getLeft().getValue()).getValue());
		if(getRight().getValue().getClass() == Bool.class)
			return new Bool(((Bool) getRight().getValue()).getValue() != ((Bool) getLeft().getValue()).getValue());
		if(getRight().getValue().getClass() == Entity.class)
			return new Bool(((Entity) getRight().getValue()).getValue() != ((Entity) getLeft().getValue()).getValue());
		return new Bool(true);
	}
	
	@Override
	public String typecheck(){
		String leftTypeCheck = getLeft().typecheck();
		String rightTypeCheck = getRight().typecheck();
		if(!(leftTypeCheck + rightTypeCheck).equals(""))
			return leftTypeCheck + rightTypeCheck;
		if(getLeft().getValue() == null){
			if(getRight().getValue() == null || getRight().getValue().getClass() == Entity.class)
				return "";
			else return "Typecast error at line " + getLine() + ", column " + getColumn() + ".\n";
		}
		if(getRight().getValue() == null){
			if(getLeft().getValue() == null || getLeft().getValue().getClass() == Entity.class)
				return "";
			else return "Typecast error at line " + getLine() + ", column " + getColumn() + ".\n";
		}		
		if(getLeft().getValue().getClass() != getRight().getValue().getClass())
			return "Typecast error at line " + getLine() + ", column " + getColumn() + ".\n";
		else return "";
	}
}
